package com.shiguo365.market.presenter.implement;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v7.widget.Toolbar;
import android.util.Log;

import com.alibaba.fastjson.JSONObject;
import com.shiguo365.market.R;
import com.shiguo365.market.display.activity.ForgetActivity;
import com.shiguo365.market.display.util.ToastUtils;
import com.shiguo365.market.display.view.IForgetView;
import com.shiguo365.market.presenter.contract.IForgetPresenter;


import biz.yfsoft.api.ae.api.AEClient;
import biz.yfsoft.api.ae.api.AEParam;
import biz.yfsoft.api.ae.api.BaseAECallback;
import butterknife.BindView;

/**
 * Created by james on 16/7/30.
 */
public class ForgetPresenter implements IForgetPresenter {

    private static final String TAG = "ForgetPresenter";
    private IForgetView iForgetView;
    private Activity activity;


    public ForgetPresenter(@NonNull Activity activity,@NonNull IForgetView forgetView){
        this.activity = activity;
        this.iForgetView = forgetView;
    }

    @Override
    public void forget(String username, String code, String pwd) {
        AEClient _client = new AEClient("shiguo.user.findPassword");
        AEParam aeParam =new AEParam();

        aeParam.set("phone",username);              //手机号
        aeParam.set("code",code);                   //短信验证码
        aeParam.set("password",pwd);                //登录密码
        _client.call(aeParam,new BaseAECallback() {

            @Override
            public void onSuccess(JSONObject a) {
                Log.d(TAG,"onSuccess");
                iForgetView.showForgetMessages("恭喜您密码重置成功,系统正在为你服务");
                iForgetView.forgetSuccess();
            }

            @Override
            public void onError( String errno, String message) {
                Log.e(TAG,"onFailure ......." + errno + ";message:" + message);


                iForgetView.showForgetMessages("对不起,请求失败,失败原因:"+message);
            }

            @Override
            public void onFinally(String s) {
                Log.d(TAG,"onFinally,,,,,");
            }
        });
    }

    /**
     * 获取六位随机码
     * @param mobile
     * @auto James 2016-07-28
     */
    @Override
    public void smscheck(String mobile) {
        AEClient _client = new AEClient("shiguo.user.juheSMS");
        AEParam aeParam =new AEParam();

        String tpl_id = "17582";
        aeParam.set("mobile",mobile);
        aeParam.set("tpl_id",tpl_id);    //短信模版id
        aeParam.set("source",2);         //1：注册，2：找回密码
        _client.call(aeParam,new BaseAECallback() {

            @Override
            public void onSuccess(JSONObject a) {
                Log.d(TAG,a.toJSONString());
                //iRegisterView.SmsSuccess();

            }

            @Override
            public void onError( String errno, String message) {
                Log.e(TAG,"onFailure ......." + errno + ";message:" + message);
                iForgetView.showForgetMessages("短信接口未收到请求,请再尝试发送请求");
            }

            @Override
            public void onFinally(String s) {
                //mView.onGetUserInfoFinished();
                Log.d(TAG,"zzzzz");
            }
        });
    }
}
